<template>
	<view class="main">
		<view class="logo">
			<image src="../../static/mrimg.png" mode="aspectFit"></image>
		</view>
		<view class="title">方正点餐</view>
		<view class="btn" v-if="token==''">
			<!-- <view><u-icon name="weixin-fill" size="44rpx"></u-icon></view> -->
			<button hover-class='none' v-if="ischecked" open-type="getPhoneNumber" @getphonenumber="getUserPhone">一键登录 (注册)</button>
			<button hover-class='none' v-if="!ischecked" @click="checkxy">一键登录 (注册)</button>
		</view>
		<view class="btn" v-else>
			<button hover-class='none' @click="logins">一键登录 (注册)</button>
		</view>
		<view class="look">
			<view>
				<checkbox-group @change="checkboxChange">
					<label>
						<checkbox :checked="ischecked" value="1" color="#CB1717" style="transform:scale(0.7)" />
						确认签署
					</label>
				</checkbox-group>
			</view><text @tap="jump('fw')">《服务协议》</text><text @tap="jump('ys')">《隐私协议》</text>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				statusBarHeight: getApp().globalData.statusBarHeight,
				statusBarHeight1: getApp().globalData.statusBarHeight1,
				img_url: app.globalData.img_urls,
				fw_des: '',
				ys_des: '',
				fwShow: false,
				ysShow: false,
				ischecked: false,
				token:'',
				channel_id:'',
				channel_url_id:'',
				channel_user_id:''
			}
		},
		onLoad(options) {
			
		},
		onShow() {
			this.getOpen()
		},

		methods: {
			getOpen(){
				const _this = this
				uni.login({
					timeout: 6000,
					success: (res) => {
						var data = {
							wxcode: res.code,
						}
						app.globalData.api.request('index/getOpen', data,
							"POST", 'form').then(res => {
							//console.log(res)
							if (res.code == 0) {
								this.token = res.data.token
								
							} else {
								this.token = ''
							}
						})
				
					},
				})
				
			},
			logins(){
				uni.setStorageSync('token', this.token)
				uni.showToast({
					title: '登录成功~',
					icon: 'none',
					duration: 2000,
					success: function() {
						setTimeout(function() {
							wx.navigateBack({
							        delta: 0,
							})
							// uni.reLaunch({
							// 	url:'/pages/index/index'
							// });
						}, 1000);
					}
				});
			},
			checkxy(){
				return app.globalData.show('请勾选协议');
			},
			jump(type) {
				uni.navigateTo({
					url: '/subcontract/xydes/xydes?type=' + type
				})
			},
			checkboxChange: function(e) {
				var values = e.detail.value;
				if (values.length > 0) {
					this.ischecked = true;
				} else {
					this.ischecked = false;
				}
			},
			getUserPhone(e) {
				const _this = this
				uni.login({
					timeout: 6000,
					success: (res) => {
						var data = {
							wxcode: res.code,
							code: e.detail.code,
							name:'',
							pic:'',
						}
						app.globalData.api.request('index/gettel', data,
							"POST", 'form').then(res => {
							//console.log(res)
							if (res.code == 0) {
								uni.setStorageSync('token', res.data.token)
								uni.showToast({
									title: '登录成功~',
									icon: 'none',
									duration: 2000,
									success: function() {
										setTimeout(function() {
											wx.navigateBack({
											        delta: 0,
											})
											// uni.reLaunch({
											// 	url:'/pages/index/index'
											// });
										}, 1000);
									}
								});
							} else {
								return app.globalData.show(res.msg);
							}
						})

					},
				})
			},
		}
	}
</script>

<style lang="scss">
	.pop1 {
		padding: 61rpx 34rpx;
		border-radius: 26rpx;
		font-weight: 400;
		font-size: 34rpx;
		color: #727272;
		max-height: 700rpx;
		overflow-y: auto;
	}

	.main {
		font-family: PingFang SC;
		text-align: center;
		height:auto;
		width:100%;
	}
	page{
		background:url($IMG_URL+'/qtbjimg.png')no-repeat;
		background-size: 100% auto;
		background-position: bottom left;
	}
	.logo {
		width: 146rpx;
		height: 146rpx;
		background: #3660F6;
		border-radius: 50%;
		margin: 249rpx auto 30rpx;
		font-weight: bold;
		font-size: 28rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.title {
		font-weight: bold;
		font-size: 44rpx;
		color: #1F1F1F;
	}

	.btn {
		margin: 338rpx auto 31rpx;
		background: #FADD43;
		border-radius: 50rpx;
		padding: 14rpx 90rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #FFFFFF;
		display: table;
	}

	.btn button {
		float: left;
		display: inline-block;
		line-height: 66rpx;
		background: #FADD43;
		font-weight: bold;
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.btn button::after {

		border: none;
	}

	.btn>view:nth-child(1) {
		float: left;
		margin-top: 10rpx;
	}

	.look {
		font-weight: 400;
		font-size: 28rpx;
		color: #727272;
		text-align: center;
	}

	.look>view:nth-child(1) {
		display: inline-block;
	}


	.look text {
		color: #333333;
	}
</style>